package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.annotion.BussinessLog;
import com.stylefeng.guns.core.common.annotion.Permission;
import com.stylefeng.guns.core.common.constant.dictmap.DeptDict;
import com.stylefeng.guns.core.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.core.common.exception.BizExceptionEnum;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.node.ZTreeNode;
import com.stylefeng.guns.core.util.OSSUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.model.Dept;
import com.stylefeng.guns.modular.system.service.IDeptService;
import com.stylefeng.guns.modular.system.warpper.DeptWarpper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 部门控制器
 *
 * @author fengshuonan
 * @Date 2017年2月17日20:27:22
 */
@Controller
@RequestMapping("/common")
public class CommonController extends BaseController {

    private String PREFIX = "/system/dept/";
    private int expires=60000;


    /**
     * 通用上传方法
     */
    @RequestMapping(value = "/commonUpload", method = RequestMethod.POST)
    public ResponseEntity commonUpload(@RequestParam("file") MultipartFile file){
        Map returnMap=new HashMap();
        try {
            String fileName= OSSUtil.putSingleFile(file.getBytes(),file.getOriginalFilename());
            String filePath= OSSUtil.getFileUrl(fileName,expires);
            returnMap.put("fileName",fileName);
            returnMap.put("filePath",filePath);
            returnMap.put("status",false);
        }catch (Exception e)
        {
            e.printStackTrace();
        }

        return new ResponseEntity(returnMap, HttpStatus.OK);
    }
}
